package com.lagou;

import java.util.concurrent.BlockingQueue;

public class Consumer implements Runnable {

    private BlockingQueue<Order> blockingQueue;

    public Consumer(BlockingQueue<Order> blockingQueue) {
        this.blockingQueue = blockingQueue;
    }

    @Override
    public void run() {
        while (true) {
            //每200毫秒处理一个
            try {
                Order order = blockingQueue.take();
                System.out.println(order.getId() + "号订单被处理");
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
